import request from '@/utils/request'

// 查询地区列表
export function listArea(query) {
  return request({
    url: '/business/area/list',
    method: 'get',
    params: query
  })
}

// 查询地区详细
export function getArea(areaId) {
  return request({
    url: '/business/area/' + areaId,
    method: 'get'
  })
}

// 新增地区
export function addArea(data) {
  return request({
    url: '/business/area',
    method: 'post',
    data: data
  })
}

// 修改地区
export function updateArea(data) {
  return request({
    url: '/business/area',
    method: 'put',
    data: data
  })
}

// 提交地区供审批
export function submitArea(areaId) {
  return request({
    url: '/business/area/submit/' + areaId,
    method: 'delete'
  })
}

// 审批通过地区
export function passArea(areaId) {
  return request({
    url: '/business/area/pass/' + areaId,
    method: 'delete'
  })
}

// 反审批退回地区
export function backArea(areaId) {
  return request({
    url: '/business/area/back/' + areaId,
    method: 'delete'
  })
}

// 删除地区
export function delArea(areaId) {
  return request({
    url: '/business/area/' + areaId,
    method: 'delete'
  })
}

// 导出地区
export function exportArea(query) {
  return request({
    url: '/business/area/export',
    method: 'get',
    params: query
  })
}

// 获取所有地区
export function getAreas() {
  return request({
    url: '/business/area/all',
    method: 'get'
  })
}

// 回显地区
export function selectAreaLabel(datas, value) {
  var actions = [];
  Object.keys(datas).some((key) => {
    if (datas[key].areaId.toString() == ('' + value)) {
      actions.push(datas[key].areaTitle);
      return true;
    }
  })
  return actions.join('');
}
